<template>
	<view>
		<view class="pc-view">
			<view class="is-login"></view>
			<view class="from-view-pc">
				<view class="title-view">
					<view class="row">
						<view class="title-text">找回密码</view>
						<view class="title-desc">
							<view>NUOZHONG</view>
							<view style="margin-top: -2px;">Pass Word</view>
						</view>
					</view>

					<view class="step-view">
						<view class="step-text">{{stepIndex}}</view>
						<view>/3</view>
					</view>
				</view>
				<block v-if="stepIndex == 1">
					<view class="form-item">
						<view class="form-label">
							<view>手</view>
							<view>机</view>
							<view>号</view>
						</view>
						<view class="division"></view>
						<view class="form-content">
							<input type="number" v-model="formData.phoneNumber" placeholder="请输入手机号" class="input-css"
								placeholder-class="plac-css" maxlength="11" />
						</view>
					</view>
					<view class="form-item" style="padding: 10px 29px;padding-right: 10px;">
						<view class="form-label">
							<view>验</view>
							<view>证</view>
							<view>码</view>
						</view>
						<view class="division"></view>
						<view class="form-content">
							<input type="number" v-model="formData.phoneCode" placeholder="请输入验证码" class="input-css"
								placeholder-class="plac-css" maxlength="6" />
							<view class="code-button" @click="getCode">
								{{codeTime != 60 ? codeTime + 's后重新获取' : '获取验证码'}}
							</view>
						</view>
					</view>
				</block>
				<block v-else-if="stepIndex == 2">
					<view class="form-item">
						<view class="form-label">
							<view>新</view>
							<view>密</view>
							<view>码</view>
						</view>
						<view class="division"></view>
						<view class="form-content">
							<input v-model="formData.password" password placeholder="请输入密码" class="input-css"
								placeholder-class="plac-css" maxlength="32" />
						</view>
					</view>
					<view class="form-item">
						<view class="form-label">
							<view>确</view>
							<view>认</view>
							<view>密</view>
							<view>码</view>
						</view>
						<view class="division"></view>
						<view class="form-content">
							<input v-model="formData.confirmPassword" password placeholder="请输入密码" class="input-css"
								placeholder-class="plac-css" maxlength="32" />
						</view>
					</view>
				</block>
				<block v-else-if="stepIndex == 3">
					<view class="succeed-view">
						<image src="/static/pc/forgetPassword-succeed.png" class="succeed-icon"></image>
						<view class="succeed-text">登录密码已重置，请点击下方按钮登录</view>
					</view>
				</block>
				<view style="height: 34px;"></view>
				<view v-if="stepIndex == 1" class="button-view-pc button-primary" @click="onStepOne">下一步</view>
				<view v-else-if="stepIndex == 2" class="button-view-pc button-primary" @click="onStepTwo">下一步</view>
				<view v-else-if="stepIndex == 3" class="button-view-pc button-primary" @click="onStepThree">去登陆
				</view>
			</view>
			<view class="pc-view-content">
				<image src="@/static/pc/login-bg.png" class="login-bg" mode="aspectFill"></image>
				<Footer></Footer>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				stepIndex: 1,
				codeTime: 60,
				timer: null,
				formData: {
					phoneNumber: '',
					phoneCode: '',
					password: '',
					confirmPassword: '',
					advisoryNumber: ''
				}
			};
		},
		onLoad(options) {

		},
		methods: {
			onStepOne() {
				const regex = uni.$util.regex
				const showToast = uni.$util.showToast
				if (!this.formData.phoneNumber) return showToast('请输入手机号')
				if (!regex.phone.test(this.formData.phoneNumber)) return showToast('请输入正确的手机号')
				if (!this.formData.phoneCode) return showToast('请输入验证码')
				if (this.formData.phoneCode.length < 6) return showToast('请输入正确的验证码')
				this.stepIndex = 2
			},
			onStepTwo() {
				const regex = uni.$util.regex
				const showToast = uni.$util.showToast
				if (!this.formData.password) return showToast('请输入密码')
				if (this.formData.password.length < 6) return showToast('密码不能小于6位')
				if (!this.formData.confirmPassword) return showToast('请输入确认密码')
				if (this.formData.password != this.formData.confirmPassword) return showToast('密码不一致')
				this.stepIndex = 3
			},
			onStepThree() {
				this.navigateBack('/pages/login/login')
			},
			/**
			 * 获取验证码
			 */
			async getCode() {
				const regex = uni.$util.regex
				const showToast = uni.$util.showToast
				if (this.codeTime != 60 || this.timer) return
				if (!this.formData.phoneNumber) return showToast('请输入手机号')
				if (!regex.phone.test(this.formData.phoneNumber)) return showToast('请输入正确的手机号')
				uni.$util.showLoading()
				const res = await uni.$api.sendCode({
					phoneNumber: this.formData.phoneNumber,
					sendType: '1'
				}).finally(uni.finally)
				this.timer = setInterval(() => {
					this.codeTime--
					if (this.codeTime === 0) {
						this.codeTime = 60
						this.clearIntervalTimer()
					}
				}, 1000)
				uni.$util.showToast('已发送验证码, 请注意查收')
			},
			/**
			 * 取消定时器
			 */
			clearIntervalTimer() {
				clearInterval(this.timer)
				this.timer = null
			}
		}
	}
</script>

<style scoped lang="scss">
	.pc-view {
		width: 100%;
		@extend .column;
		align-items: flex-end;
		background: wheat;
		background: url('@/static/pc/login-bg.png');
		background-size: cover;
		position: relative;

		.is-login {
			height: 238px;
		}

		.from-view-pc {
			width: 524px;
			padding: 37px 50px;
			background: #FFFFFF;
			margin-right: 192px;
			position: relative;
			z-index: 2;

			.title-view {
				width: 100%;
				margin-bottom: 38px;
				@extend .row-between;

				.title-text {
					font-weight: 600;
					font-size: 34px;
					color: #470300;
					margin-right: 6px;
				}

				.title-desc {
					font-size: 14px;
					color: #470300;
				}

				.step-view {
					@extend .row;
					align-items: baseline;
					font-size: 22px;

					.step-text {
						font-size: 34px;
					}
				}
			}

			.form-item {
				width: 100%;
				padding: 18px 29px;
				background: #F6F6F6;
				border-radius: 31px;
				@extend .row-between;

				.form-label {
					width: 77px;
					@extend .row-between;
					font-size: 19px;
					color: #470300;
				}

				.division {
					width: 1px;
					height: 18px;
					background: #470300;
				}

				.form-content {
					@extend .row-between;
					width: calc(100% - 77px - 30px);

					.input-css {
						flex: 1;
						font-size: 19px;
					}

					.plac-css {
						font-size: 19px;
						color: #969595;
					}

					.code-button {
						padding: 10px 17px;
						font-size: 17px;
						color: #FF453B;
						border-radius: 22px;
						border: 1px solid #FF453B;
					}
				}
			}

			.form-item+.form-item {
				margin-top: 14px;
			}

			.succeed-view {
				width: 100%;
				padding-top: 8px;

				@extend .column;

				.succeed-icon {
					width: 72px;
					height: 72px;
				}

				.succeed-text {
					font-weight: 400;
					font-size: 19px;
					color: #470300;
					margin-top: 34px;
				}
			}

			.button-view-pc {
				width: 100%;
				height: 62px;
				@extend .column;
				background: #FFFFFF;
				border-radius: 31px;
				border: 1px solid #FF453B;
				font-size: 22px;
				color: #FF453B;
			}

			.button-primary {
				background: #FF453B;
				color: white;
			}

			.button-text {
				height: initial;
				border: none;
				background: #FFFFFF;
			}

			.button-view-pc+.button-view-pc {
				margin-top: 14px;
			}

			.button-view-pc+.button-text {
				margin-top: 24px;
			}
		}

		.pc-view-content {
			width: 100%;
			position: absolute;
			left: 0;
			top: 0;
			z-index: 1;

			.login-bg {
				width: 100%;
				min-height: 680px;
				height: calc(100vh - 208px);
				vertical-align: sub;
			}
		}
	}


	@media only screen and (max-width: 908px) {
		.pc-view {
			align-items: center;

			.from-view-pc {
				margin-right: 0;
			}
		}
	}

	@media only screen and (max-width: 584px) {
		.pc-view {

			.from-view-pc {
				width: calc(100% - 60px);
			}
		}
	}
</style>